/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sysdance.aplicativo.visao.operacoes;

import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;
import org.syndance.aplicativo.enums.CompararPorCurso;
import org.syndance.aplicativo.enums.PesquisarPorCurso;
import org.sysdance.aplicativo.modelo.Curso;
import org.sysdance.aplicativo.util.visao.JanelaDialogo;
import org.sysdance.aplicativo.visao.tela.TelaCurso;

/**
 * <<<<<<< .miness
 *s
 *
 * ======= @author gocard
 *
 * >>>>>>> .r27
 */
public class OpCurso extends JanelaDialogo {

    TelaCurso telaCurso;

    /**
     * Creates new form NewJDialog
     */
    public OpCurso(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

        for (CompararPorCurso compararpor : CompararPorCurso.values()) {
            cbCompararPor.addItem(compararpor);
        }
        for (PesquisarPorCurso pesquisarpor : PesquisarPorCurso.values()) {
            cbPesquisarPor.addItem(pesquisarpor.name());
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelCurso = new javax.swing.JPanel();
        jblPesquisar = new javax.swing.JLabel();
        cbPesquisarPor = new javax.swing.JComboBox();
        jblCompararPor = new javax.swing.JLabel();
        cbCompararPor = new javax.swing.JComboBox();
        tfCampoBusca = new javax.swing.JTextField();
        btnConsultarCurso = new javax.swing.JButton();
        jblDe = new javax.swing.JLabel();
        tfCompararDe = new javax.swing.JTextField();
        jblAte = new javax.swing.JLabel();
        tfCompararAte = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblListarCurso = new javax.swing.JTable();
        btnIncluirCurso = new javax.swing.JButton();
        btnAlterarCurso = new javax.swing.JButton();
        btnStatusCurso = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanelCurso.setBorder(javax.swing.BorderFactory.createTitledBorder("Curso:"));
        jPanelCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jblPesquisar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblPesquisar.setText("Pesquisar por:");

        jblCompararPor.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblCompararPor.setText("Comparar por:");

        cbCompararPor.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbCompararPorItemStateChanged(evt);
            }
        });

        btnConsultarCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnConsultarCurso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sysdance/aplicativo/imagens/consultar.png"))); // NOI18N
        btnConsultarCurso.setText("Consultar");

        jblDe.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblDe.setText("De");

        jblAte.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jblAte.setText("Até");

        tblListarCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tblListarCurso.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Id:", "Descrição:", "Idade Mínima", "Período / Mês", "Valor", "Status"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblListarCurso);

        btnIncluirCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnIncluirCurso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sysdance/aplicativo/imagens/adicionar.png"))); // NOI18N
        btnIncluirCurso.setText("Incluir");
        btnIncluirCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnIncluirCursoActionPerformed(evt);
            }
        });

        btnAlterarCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnAlterarCurso.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sysdance/aplicativo/imagens/alterar.png"))); // NOI18N
        btnAlterarCurso.setText("Alterar");
        btnAlterarCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarCursoActionPerformed(evt);
            }
        });

        btnStatusCurso.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        btnStatusCurso.setText("Ativar / Desativar");
        btnStatusCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStatusCursoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelCursoLayout = new javax.swing.GroupLayout(jPanelCurso);
        jPanelCurso.setLayout(jPanelCursoLayout);
        jPanelCursoLayout.setHorizontalGroup(
            jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCursoLayout.createSequentialGroup()
                .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelCursoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jblPesquisar)
                            .addComponent(cbPesquisarPor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(41, 41, 41)
                        .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jblCompararPor)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelCursoLayout.createSequentialGroup()
                                .addComponent(cbCompararPor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
                                .addComponent(tfCampoBusca, javax.swing.GroupLayout.PREFERRED_SIZE, 338, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnConsultarCurso))))
                    .addGroup(jPanelCursoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnStatusCurso)
                        .addGap(26, 26, 26)
                        .addComponent(btnAlterarCurso)
                        .addGap(26, 26, 26)
                        .addComponent(btnIncluirCurso))
                    .addGroup(jPanelCursoLayout.createSequentialGroup()
                        .addGap(299, 299, 299)
                        .addComponent(jblDe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfCompararDe, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jblAte)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tfCompararAte, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(jScrollPane1)
        );
        jPanelCursoLayout.setVerticalGroup(
            jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCursoLayout.createSequentialGroup()
                .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelCursoLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jblPesquisar)
                            .addComponent(jblCompararPor))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbPesquisarPor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbCompararPor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfCampoBusca, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnConsultarCurso))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfCompararDe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfCompararAte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanelCursoLayout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(jblAte))
                    .addGroup(jPanelCursoLayout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(jblDe)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 304, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE)
                .addGroup(jPanelCursoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAlterarCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnIncluirCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnStatusCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelCurso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanelCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        getAccessibleContext().setAccessibleName("Cadastro de Curso\n");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnIncluirCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIncluirCursoActionPerformed
        // TODO add your handling code here:

        if ((telaCurso == null) || (!telaCurso.isVisible())) {
            telaCurso = new TelaCurso(null, true);
            telaCurso.setLocationRelativeTo(this);
            telaCurso.setVisible(true);
        }
    }//GEN-LAST:event_btnIncluirCursoActionPerformed

    private void btnAlterarCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnAlterarCursoActionPerformed

    private void btnStatusCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStatusCursoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnStatusCursoActionPerformed

    private void cbCompararPorItemStateChanged(java.awt.event.ItemEvent evt) {
        if (evt.getItem() == CompararPorCurso.ENTRE) {
            boolean habilitaEntre = evt.getItem() == CompararPorCurso.ENTRE;
            tfCampoBusca.setEnabled(!habilitaEntre);
            tfCompararDe.setEnabled(habilitaEntre);
            tfCompararAte.setEnabled(habilitaEntre);
        } else if (evt.getItem() == CompararPorCurso.CONTÊM) {

            boolean habilitaContem = evt.getItem() == CompararPorCurso.CONTÊM;
            tfCampoBusca.setEnabled(habilitaContem);
            tfCompararDe.setEnabled(!habilitaContem);
            tfCompararAte.setEnabled(!habilitaContem);

        } else if (evt.getItem() == CompararPorCurso.IGUAL) {

            boolean habilitaIgual = evt.getItem() == CompararPorCurso.IGUAL;
            tfCampoBusca.setEnabled(habilitaIgual);
            tfCompararDe.setEnabled(!habilitaIgual);
            tfCompararAte.setEnabled(!habilitaIgual);
            tfCampoBusca.setText(null);

        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OpCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OpCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OpCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OpCurso.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                OpCurso dialog = new OpCurso(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterarCurso;
    private javax.swing.JButton btnConsultarCurso;
    private javax.swing.JButton btnIncluirCurso;
    private javax.swing.JButton btnStatusCurso;
    private javax.swing.JComboBox cbCompararPor;
    private javax.swing.JComboBox cbPesquisarPor;
    private javax.swing.JPanel jPanelCurso;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jblAte;
    private javax.swing.JLabel jblCompararPor;
    private javax.swing.JLabel jblDe;
    private javax.swing.JLabel jblPesquisar;
    private javax.swing.JTable tblListarCurso;
    private javax.swing.JTextField tfCampoBusca;
    private javax.swing.JTextField tfCompararAte;
    private javax.swing.JTextField tfCompararDe;
    // End of variables declaration//GEN-END:variables

}
